﻿using System;

namespace PlottingBasics.Functions
{
    /// <summary>
    /// The gaussion function and helpers
    /// </summary>
    public class Gaussian
    {

        /// <summary>
        /// Creates a gausian function which can then be called whenever!
        /// </summary>
        /// <param name="p"></param>
        /// <param name="p_2"></param>
        /// <returns></returns>
        public static Func<double, double> Gauss(double mean, double width)
        {
            double ANorm = 1 / (width * Math.Sqrt(2 * Math.PI));
            return x =>
            {
                return ANorm * Math.Exp(-(x - mean) * (x - mean) / 2.0 / width / width);
            };
        }

        /// <summary>
        /// Given a gaussian at mean and width, return the position along the x axis s.t. the
        /// integral of the probability from zero to that position is 1-prob.
        /// 
        /// So, if prob is 5%, then the return value x should be such that [0, x] contains 95% of the
        /// probability.
        /// </summary>
        /// <param name="prob"></param>
        /// <param name="BackgroundMean">mean of the gaussian</param>
        /// <param name="BackgroundWidth"></param>
        /// <returns></returns>
        public static double PositionForProb(double prob, double mean, double width)
        {
            /// CLEARLY WRONG, but a place holder!
            return mean;
        }
    }
}
